﻿using UnityEngine.UIElements;

namespace winS.UnityEditor.UIElement
{
    /// <summary>
    /// Row container.
    /// </summary>
    public class Row : EditorElement
    {
        protected internal Row(ElementFactory elementFactory) : base(elementFactory)
        {
            style.flexDirection = FlexDirection.Row;
        }

        public void Add(VisualElement visualElement, float visualElementFlexGrow)
        {
            visualElement.style.flexGrow = visualElementFlexGrow;
            Add(visualElement);
        }
        public void AddWithWidth(VisualElement visualElement, float width)
        {
            visualElement.style.SetWidth(width);
            Add(visualElement);
        }
        public void AddWithWidthPercent(VisualElement visualElement, float widthPercent)
        {
            visualElement.style.SetWidth(widthPercent, LengthUnit.Percent);
            Add(visualElement);
        }

        public Row AddToSubrow(VisualElement visualElement, float rowFlexGrow = 1f)
        {
            Row row = EditorElementUtility.elementFactory.CreateRow(rowFlexGrow);
            row.Add(visualElement);
            Add(row);
            return row;
        }
        public Column AddToSubcolumn(VisualElement visualElement, float columnFlexGrow = 1f)
        {
            Column column = EditorElementUtility.elementFactory.CreateColumn(columnFlexGrow);
            column.style.justifyContent = Justify.Center;
            column.Add(visualElement);
            Add(column);
            return column;
        }
    }
}